package com.google.gwt.sample.stockwatcher.server;


import com.google.gwt.sample.stockwatcher.client.StockAdd;
import com.google.gwt.sample.stockwatcher.client.StockPrice;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import org.hibernate.Session;

import util.HibernateUtil;

@SuppressWarnings("serial")
public class StockAddImpl extends RemoteServiceServlet implements StockAdd{
	public StockPrice getPrice(StockPrice addPrice){
		
		StockPrice news=new StockPrice();
		String name =addPrice.getName();
		String sername =addPrice.getSername();
		String phone =addPrice.getPhone();
		news.setName(name);
		news.setSername(sername);
		news.setPhone(phone);
		
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		if (session==null){
			System.out.println("NULLL");
		}
		session.beginTransaction();
		session.saveOrUpdate(news);
		session.getTransaction().commit();
		session.close();
		
		/*
			Statement statement = null;
			Connection con = null;
			try {
			con = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5433/postgres", "postgres", "hr");
			statement = con.createStatement();
			statement.executeQuery("insert into \"manual\" values (DEFAULT,'"+sername+"','"+name+"','"+phone+"')");
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			*/
			return null;
		
	}
}